# coding=utf-8
from function_utils import Human, PsUtil, Global


def mem_info():
    PsUtil.init()
    memory = PsUtil.memory()
    value = ''': - Total: {0:10}  Used: {1:10}  Buffers: {2:10}  Cached: {3:10}
: - Swap:  {4:10}  Used: {5:10}'''.format(
        Human.size(memory['total']), Human.size(memory['used']),
        Human.size(memory['buffers']), Human.size(memory['cached']),
    Human.size(memory['swap_total']), Human.size(memory['swap_used'])
    )
    percent = int(memory['mem_percent'])
    return value, percent


def write_widgets_value(data):
    value, percent = data
    data = [
        {"InfoText": value},
        {"MultiScaleBar": percent},
        {}
    ]
    Global.values_write(data)
    Global.report_info(100)


def main():
    write_widgets_value(mem_info())


if __name__ == '__main__':
    main()
